package com.gzx.plugin.tjzy.modular.call.predict.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gzx.plugin.tjzy.modular.call.predict.bo.GzxPredictCallAddBo;
import com.gzx.plugin.tjzy.modular.call.predict.bo.GzxPredictCallQueryBo;
import com.gzx.plugin.tjzy.modular.call.predict.service.GzxPredictCallImportService;
import com.gzx.plugin.tjzy.modular.call.predict.service.GzxPredictCallService;
import com.gzx.plugin.tjzy.modular.call.predict.vo.GzxPredictCallDetailVo;
import com.gzx.plugin.tjzy.modular.call.predict.vo.GzxPredictCallVo;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import vip.xiaonuo.common.annotation.CommonLog;
import vip.xiaonuo.common.annotation.CommonNoRepeat;
import vip.xiaonuo.common.pojo.CommonResult;

import java.io.IOException;

/**
 * @author zjt
 * @description
 * @date 2025/3/28 14:21
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/tjzy/predict")
public class GzxPredictCallController {

    private final GzxPredictCallImportService predictCallImportService;

    private final GzxPredictCallService predictCallService;

    /**
     * 预测外呼数据坐席导入
     *
     * @param multipartFile excel
     */
    @CommonNoRepeat
    @CommonLog("预测外呼数据坐席导入")
    @PostMapping("/importExcel")
    public CommonResult<String> importExcel(@RequestPart("predictCallAddBo") GzxPredictCallAddBo predictCallAddBo, @RequestPart("multipartFile") MultipartFile multipartFile) throws IOException {
        return predictCallImportService.importExcel(multipartFile, predictCallAddBo);
    }

    @PostMapping("/pageList")
    public CommonResult<Page<GzxPredictCallVo>> pageList(@RequestBody GzxPredictCallQueryBo predictCallQueryBo) {
        return CommonResult.data(predictCallService.pageList(predictCallQueryBo));
    }

    @PostMapping("/pageDetail")
    public CommonResult<Page<GzxPredictCallDetailVo>> pageDetail(@RequestBody GzxPredictCallQueryBo predictCallQueryBo) {
        return CommonResult.data(predictCallService.pageDetail(predictCallQueryBo));
    }

    @GetMapping("/getCallDetailById/{id}")
    public CommonResult<GzxPredictCallDetailVo> getCallDetailById(@PathVariable Long id) {
        return CommonResult.data(predictCallService.getCallDetailById(id));
    }

    @GetMapping("/delPredictCall/{batchNumber}")
    @CommonLog("删除预测外呼")
    @CommonNoRepeat
    public CommonResult<String> delPredictCall(@PathVariable String batchNumber) {
        predictCallService.delPredictCall(batchNumber);
        return CommonResult.ok();
    }

    @PostMapping("/copyPreOutCallDetail")
    @CommonLog("预测外呼数据复制")
    @CommonNoRepeat
    public CommonResult<String> copyPredictCallDetail(@RequestBody GzxPredictCallAddBo predictCallAddBo) {
        return predictCallImportService.copyPredictCallDetail(predictCallAddBo);
    }

    @GetMapping("/startCallTask/{batchNumber}")
    @CommonLog("预测外呼任务开始")
    @CommonNoRepeat
    public CommonResult<String> startCallTask(@PathVariable String batchNumber) {
        return predictCallService.startCallTask(batchNumber);
    }

    @GetMapping("/pauseCallTask/{batchNumber}")
    @CommonLog("预测外呼任务暂停")
    @CommonNoRepeat
    public CommonResult<String> pauseCallTask(@PathVariable String batchNumber) {
        return predictCallService.pauseCallTask(batchNumber);
    }

    @GetMapping("/continueCallTask/{batchNumber}")
    @CommonLog("预测外呼任务继续")
    @CommonNoRepeat
    public CommonResult<String> continueCallTask(@PathVariable String batchNumber) {
        return predictCallService.continueCallTask(batchNumber);
    }

    @GetMapping("/finishCallTask/{batchNumber}")
    @CommonLog("预测外呼任务完结")
    @CommonNoRepeat
    public CommonResult<String> finishCallTask(@PathVariable String batchNumber) {
        predictCallService.finishCallTask(batchNumber);
        return CommonResult.ok();
    }

    @GetMapping("/closeErrorTask/{taskId}")
    @CommonLog("异常任务关闭")
    @CommonNoRepeat
    public CommonResult<String> closeErrorTask(@PathVariable String taskId) {
        predictCallService.closeErrorTask(taskId);
        return CommonResult.ok();
    }

    @GetMapping("/getCallCount/{taskId}")
    public CommonResult<Integer> getCallCount(@PathVariable String taskId, @RequestParam("filterType") Integer filterType) {
        return CommonResult.data(predictCallService.getCallCount(taskId, filterType));
    }
}
